package com.wangxiaonan.wxwork.controller;

import com.wangxiaonan.wxwork.domain.Agent;
import com.wangxiaonan.wxwork.service.AgentService;
import com.wangxiaonan.wxwork.service.TokenService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;

/**
 * @Author: wangxiaonan
 * @Date: 2018/8/28
 **/
@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private TokenService tokenService;
    @Resource
    private AgentService agentService;

    @RequestMapping(value = {"/token"})
    public String index(@RequestParam(value = "agent_id") String agentId) {

        Agent agent = agentService.queryAgentById(agentId);
        String token = tokenService.getTokenString(agent.getCorpId(), agent.getSecret());
        return token;
    }
}
